package com.example.finalapplication;

import static androidx.constraintlayout.motion.utils.Oscillator.TAG;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.HashMap;

public class QiyouActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{
    ListView listView;
    Handler handler;
    SimpleAdapter listItemAdapter;
    //ProgressBar bar;
    ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qiyou);



        Intent intent6 = getIntent();
       // bar = findViewById(R.id.progressBar6);
      //listView.setEmptyView(bar);
        listView = findViewById(R.id.mylist6);
        listView.setOnItemClickListener(this);
         ArrayList<HashMap<String, String>> listItems = new ArrayList<HashMap<String, String>>();
        listItemAdapter = new SimpleAdapter(this,
                listItems,
                R.layout.item_three,
                new String[]{"Itemcity", "Itemtwo","Itemfive","Itemeight","Itemzero"},
                new int[]{R.id.city, R.id.two,R.id.five,R.id.eight,R.id.zero});

        listView.setAdapter(listItemAdapter);

        handler = new Handler(Looper.myLooper()) {

            @Override
            public void handleMessage(@NonNull Message msg) {
                if (msg.what == 6) {
                    list = (ArrayList<HashMap<String, String>>) msg.obj;
                    listItemAdapter = new SimpleAdapter(QiyouActivity.this,
                            list,
                            R.layout.item_three,
                            new String[]{"city", "two","five","eight","zero"},
                            new int[]{R.id.city, R.id.two,R.id.five,R.id.eight,R.id.zero}
                    );
             MineAdapterThree MineAdapterThree=new MineAdapterThree(QiyouActivity.this,
                            R.layout.item_three,list);

                    listView.setAdapter(listItemAdapter);
                }
                super.handleMessage(msg);
            }
        };

        ThirdTask ThirdTask = new ThirdTask();
        ThirdTask.setHandler(handler);

        Thread t = new Thread(ThirdTask);
        t.start();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position);
        Log.i(TAG, "onItemClick:position=" + position);

        String City = map.get("city");
        String Two = map.get("two");
         String Five = map.get("five");
          String Eight = map.get("eight");
           String Zero = map.get("zero");
        Intent Calculation2 = new Intent(QiyouActivity.this, Calculation2.class);
        Calculation2.putExtra("City", City);
        Calculation2.putExtra("Two", Two);
        Calculation2.putExtra("Five", Five);
        Calculation2.putExtra("Eight", Eight);
        Calculation2.putExtra("Zero", Zero);

        startActivity(Calculation2);


    }
}
